<template>
  <div class="login-container">

    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">

      <div class="title-container">
        <h3 class="title">欢迎使用维数管理系统</h3>
        <div align="center">
          <el-button type="text" @click="openLogin"><h2>登陆</h2></el-button> |
          <el-button type="text" @click="openRegiest"><h2>注册</h2></el-button>
        </div>
      </div>
      <div v-if="login">
        <el-form-item prop="username">
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <el-input
            ref="username"
            v-model="loginForm.username"
            placeholder="请输入用户名"
            name="username"
            type="text"
            tabindex="1"
            autocomplete="on"
          />
        </el-form-item>

        <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
          <el-form-item prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              :type="passwordType"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              autocomplete="on"
              @blur="capsTooltip = false"
              @keyup.enter.native="handleLogin"
            />
            <span class="show-pwd" @click="showPwd">
              <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
            </span>
          </el-form-item>
        </el-tooltip>
        <el-form-item prop="code">
          <span class="svg-container">
            <svg-icon icon-class="lock" />
          </span>
          <el-input v-model="loginForm.code" style="width: 200px" placeholder="请输入验证码" />
          <el-button v-if="show" style="margin-left: 100px" @click="getPhoneCode(null)">获取验证码</el-button>
          <span v-if="!show" style="margin-left: 100px;color: white">{{ count }}s后重新获取</span>

          <div class="login-code">
            <img :src="codeUrl" class="login-code-img" @click="codeOnclick()">
          </div>
        </el-form-item>
        <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登陆</el-button>
      </div>
    </el-form>
    <!--  注册  -->
    <div v-if="registe">

      <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules" label-width="100px" class="regis-form" autocomplete="on" label-position="left">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="ruleForm.username" />
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="ruleForm.mobile" />
        </el-form-item>
        <el-form-item label="验证码" prop="code">
          <el-input v-model="ruleForm.code" />
          <i class="el-icon-edit" @click="getcode">获取验证码</i>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="ruleForm.password" type="password" autocomplete="off" />
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input v-model="ruleForm.checkPass" type="password" autocomplete="off" />
        </el-form-item>
        <el-form-item label="用户类型" prop="apartmentOperatorType">
          <el-radio-group v-model="ruleForm.apartmentOperatorType">
            <el-radio label="1">个人职业房东</el-radio>
            <el-radio label="2">公司化公寓</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">注册</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>

      <!--<el-form ref="regis" :model="regisForm" :rules="regisRules" class="regis-form" autocomplete="on" label-position="left">
        <el-form-item prop="username">
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <el-input
            ref="username"
            v-model="regisForm.username"
            placeholder="请输入用户名"
            name="username"
            type="text"
            tabindex="1"
            autocomplete="on"
          />
        </el-form-item>

        <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
          <el-form-item prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :key="passwordTypeRegisTwo"
              ref="passwordTypeRegisTwo"
              v-model="regisForm.password"
              :type="passwordTypeRegisTwo"
              placeholder="请输入密码"
              name="passwordTypeRegisTwo"
              tabindex="2"
              autocomplete="on"
              @blur="capsTooltip = false"
            />
            <span class="show-pwd" @click="showPwdTwo">
              <svg-icon :icon-class="passwordTypeRegisTwo === 'passwordTypeRegisTwo' ? 'eye' : 'eye-open'" />
            </span>
          </el-form-item>
        </el-tooltip>
        <el-form-item prop="passwordTwo">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordTypeTwo"
            ref=" passwordTypeTwo"
            v-model="regisForm.passwordTwo"
            :type="passwordTypeTwo"
            placeholder="请确认密码"
            name="passwordTypeTwo"
            tabindex="3"
            autocomplete="on"
          />
          <span class="show-pwd" @click="showPwdThree">
            <svg-icon :icon-class="passwordTypeTwo=== 'passwordTypeTwo' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
        <el-form-item style="background-color:transparent; border:transparent">
          <el-radio v-model="regisForm.regisType" label="1" style="color: white">个体商户</el-radio>
          <el-radio v-model="regisForm.regisType" label="2" style="color: white">公司</el-radio>
        </el-form-item>
        <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleRegistered">注册</el-button>

      </el-form>-->
    </div>

    <div align="center">
      <el-button type="primary" style="width: 200px" @click="showDialog=true">
        第三方登陆
      </el-button>
    </div>

    <el-dialog title="Or connect with" :visible.sync="showDialog">
      Can not be simulated on local, so please combine you own business simulation! ! !
      <br>
      <br>
      <br>
      <social-sign />
    </el-dialog>

    <el-dialog title="分散式" :visible.sync="dialogFormVisible">
      <el-form ref="form" :model="form" :rules="rules2" class="demo-ruleForm">
        <el-form-item label="公司名称" prop="name" :label-width="formLabelWidth">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="负责人姓名" prop="legalPersonName" :label-width="formLabelWidth">
          <el-input v-model="form.legalPersonName" />
        </el-form-item>
        <el-form-item label="身份证号" prop="certNum" :label-width="formLabelWidth">
          <el-input v-model="form.certNum" />
        </el-form-item>
        <el-form-item label="身份证正面照" prop="certPicture" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess1"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl1" :src="imageUrl1" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证反面照" prop="certPicture1" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess2"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl2" :src="imageUrl2" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证手持照" prop="certPicture2" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess3"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl3" :src="imageUrl3" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="城市地区" prop="province" :label-width="formLabelWidth">
          <el-select v-model="form.province" placeholder="省" @change="getCitys">
            <el-option
              v-for="item in provinces"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>

          <el-select v-model="form.city" prop="city" placeholder="市" @change="getCountrys">
            <el-option
              v-for="item in citys"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>

          <el-select v-model="form.county" prop="county" placeholder="区">
            <el-option
              v-for="item in countrys"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址" prop="address" :label-width="formLabelWidth">
          <el-input v-model="form.address" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm2('form')">立即创建</el-button>
          <el-button @click="resetForm2('form')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="集中式" :visible.sync="dialogTableVisible">
      <el-form ref="form" :model="form" :rules="rules2" class="demo-ruleForm">
        <el-form-item label="公司名称" prop="name" :label-width="formLabelWidth">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="负责人姓名" prop="legalPersonName" :label-width="formLabelWidth">
          <el-input v-model="form.legalPersonName" />
        </el-form-item>
        <el-form-item label="身份证号" prop="certNum" :label-width="formLabelWidth">
          <el-input v-model="form.certNum" />
        </el-form-item>
        <el-form-item label="身份证正面照" prop="certPicture" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess1"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl1" :src="imageUrl1" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证反面照" prop="certPicture1" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess2"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl2" :src="imageUrl2" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证手持照" prop="certPicture2" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess3"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl3" :src="imageUrl3" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="营业执照" prop="url" :label-width="formLabelWidth">
          <el-upload
            class="avatar-uploader"
            action="http://127.0.0.1/api/sys/wish/upload/pic"
            :show-file-list="false"
            :on-success="handleAvatarSuccess4"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl4" :src="imageUrl4" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>
        <el-form-item label="城市地区" prop="province" :label-width="formLabelWidth">
          <el-select v-model="form.province" placeholder="省" @change="getCitys">
            <el-option
              v-for="item in provinces"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>

          <el-select v-model="form.city" prop="city" placeholder="市" @change="getCountrys">
            <el-option
              v-for="item in citys"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>

          <el-select v-model="form.county" prop="county" placeholder="区">
            <el-option
              v-for="item in countrys"
              :key="item.regionId"
              :label="item.regionName"
              :value="item.regionId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址" prop="address" :label-width="formLabelWidth">
          <el-input v-model="form.address" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm2('form')">立即创建</el-button>
          <el-button @click="resetForm2('form')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import { validUsername } from '@/utils/validate'
import SocialSign from './components/SocialSignin'
import axios from 'axios'

export default {
  name: 'Login',
  components: { SocialSign },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.ruleForm.password) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入用户名称'))
      } else {
        callback()
      }
    }
    const validateUsernameRegis = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入用户名称'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    const validatePasswordRegis = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    const validateCode = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入验证码'))
      } else {
        callback()
      }
    }
    const validatePasswordTwo = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请确认密码'))
      } else if (value !== this.regisForm.password) {
        callback(new Error('两次密码不一致'))
      } else {
        callback()
      }
    }
    return {
      imageUrl1: '',
      imageUrl2: '',
      imageUrl3: '',
      imageUrl4: '',
      provinces: [],
      citys: [],
      countrys: [],
      rules2: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        legalPersonName: [
          { required: true, message: '请输入法人', trigger: 'blur' }
        ],
        certNum: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        certPicture: [
          { required: true, message: '请上传正面身份证', trigger: 'blur' }
        ],
        certPicture2: [
          { required: true, message: '请上传反面身份证', trigger: 'blur' }
        ],
        certPicture3: [
          { required: true, message: '请上传手持身份证', trigger: 'blur' }
        ],
        url: [
          { required: true, message: '请上传营业执照', trigger: 'blur' }
        ],
        province: [
          { required: true, message: '请选择省', trigger: 'blur' }
        ],
        city: [
          { required: true, message: '请选择市', trigger: 'blur' }
        ],
        county: [
          { required: true, message: '请选择区', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ]
      },
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        corporation: null,
        name: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        url: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null

      },
      formLabelWidth: '120px',
      ruleForm: {
        username: '',
        password: null,
        mobile: '',
        apartmentOperatorType: null,
        code: null,
        type: null,
        checkPass: '',
        userId: null
      },
      rules: {
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        checkPass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ],
        apartmentOperatorType: [
          { required: true, message: '请选择商户类型', trigger: 'blur' }
        ]
      },
      codeUrl: '',
      show: true,
      count: '',
      timer: null,
      login: true,
      registe: false,
      loginForm: {
        username: '',
        password: '',
        grant_type: 'password'
      },
      regisForm: {
        username: '',
        password: '',
        passwordTwo: '',
        regisType: ''
      },
      regisRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsernameRegis }],
        password: [{ required: true, trigger: 'blur', validator: validatePasswordRegis }],
        passwordTwo: [{ required: true, trigger: 'blur', validator: validatePasswordTwo }]
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }],
        code: [{ required: true, trigger: 'blur', validator: validateCode }]
      },
      passwordType: 'password',
      passwordTypeRegisTwo: 'password',
      passwordTypeTwo: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
      redirect: undefined,
      otherQuery: {}
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        const query = route.query
        if (query) {
          this.redirect = query.redirect
          this.otherQuery = this.getOtherQuery(query)
        }
      },
      immediate: true
    }
  },
  created() {
    // window.addEventListener('storage', this.afterQRScan)
    /* let time=localStorage.getItem("time");
    this.getPhoneCode(time);*/

    this.axios.get('http://127.0.0.1/api/sys/wish/sys-region/getArea?pid=' + 1).then((response) => {
      this.provinces = response.data.obj
    })
    this.getPhoneCode()
  },
  mounted() {
    if (this.loginForm.username === '') {
      this.$refs.username.focus()
    } else if (this.loginForm.password === '') {
      this.$refs.password.focus()
    }
  },
  destroyed() {
    // window.removeEventListener('storage', this.afterQRScan)
  },
  methods: {
    openLogin() {
      this.login = true
      this.registe = false
    },
    openRegiest() {
      this.login = false
      this.registe = true
    },
    toRegistered() {
      location.href = 'registered'
    },
    checkCapslock(e) {
      const { key } = e
      this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
    },
    getPhoneCode(time) {
      this.loginForm.randomStr = new Date().getTime()
      const TIME_COUNT = 60
      /* let TIME_COUNT = (new Date()).getTime()+6000;
      if (time!=null){
        TIME_COUNT=time;
      }*/
      localStorage.setItem('time', JSON.stringify(TIME_COUNT))
      /* this.countDownTime= Math.ceil((TIME_COUNT - (new Date()).getTime()) / 1000)*/
      if (!this.timer) {
        this.count = TIME_COUNT
        this.show = false
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--
          } else {
            this.show = true
            clearInterval(this.timer)
            this.timer = null
          }
        }, 1000)
      }
      console.log(this.loginForm.randomStr)
      this.codeUrl = 'http://localhost/code?randomStr=' + this.loginForm.randomStr
    },
    showPwdTwo() {
      if (this.passwordTypeRegisTwo === 'password') {
        this.passwordTypeRegisTwo = ''
      } else {
        this.passwordTypeRegisTwo = 'password'
      }
      this.$nextTick(() => {
        this.$refs.passwordTypeRegisTwo.focus()
      })
    },
    showPwdThree() {
      if (this.passwordTypeTwo === 'password') {
        this.passwordTypeTwo = ''
      } else {
        this.passwordTypeTwo = 'password'
      }
      this.$nextTick(() => {
        this.$refs.passwordTypeTwo.focus()
      })
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleRegistered() {
      this.$refs.regis.validate(valid => {
        if (valid) {
          /* this.loading = true
          this.$store.dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })*/
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleLogin() {
      var $this = this
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          $this.loading = true
          axios({
            method: 'post',
            url: 'http://localhost/auth/oauth/token',
            params: $this.loginForm,
            auth: {
              username: 'android',
              password: 'android'
            }
          }).then(function(res) {
            console.log('认证返回信息:{}', res)
            // alert('成功获取token')
            localStorage.setItem('access_token', res.data.access_token)
            $this.getUsersInfo()
          })
          /* this.loading = true
          this.$store.dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })*/
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    getUsersInfo() {
      var $this = this
      axios({
        method: 'get',
        url: 'http://localhost/auth/sysuser/user/info',
        params: { access_token: localStorage.getItem('access_token') }
      }).then(function(res) {
        console.log('认证返回信息:', res)
        if (res.status === 200) {
          localStorage.setItem('username', res.data.name)
          $this.loading = true
          $this.$store.dispatch('user/login', $this.loginForm)
            .then(() => {
              $this.$router.push({ path: $this.redirect || '/', query: $this.otherQuery })
              $this.loading = false
            })
            .catch(() => {
              $this.loading = false
            })
          console.log('......')
        }
      })
    },
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== 'redirect') {
          acc[cur] = query[cur]
        }
        return acc
      }, {})
    },
    handleAvatarSuccess1(res, file) {
      this.form.certPicture = res.obj
      this.imageUrl1 = res.obj
    },
    handleAvatarSuccess2(res, file) {
      this.form.certPicture2 = res.obj
      this.imageUrl2 = res.obj
    },
    handleAvatarSuccess3(res, file) {
      this.form.certPicture3 = res.obj
      this.imageUrl3 = res.obj
    },
    handleAvatarSuccess4(res, file) {
      this.form.url = res.obj
      this.imageUrl4 = res.obj
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    getCitys() {
      this.citys = []
      this.axios.get('http://127.0.0.1/api/sys/wish/sys-region/getArea?pid=' + this.form.province).then((response) => {
        this.citys = response.data.obj
      })
    },
    getCountrys() {
      this.countrys = []
      this.axios.get('http://127.0.0.1/api/sys/wish/sys-region/getArea?pid=' + this.form.city).then((response) => {
        this.countrys = response.data.obj
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios.post('http://127.0.0.1/api/sys/wish/sys-login/reg', this.ruleForm).then((response) => {
            if (response.data.obj) {
              this.ruleForm.userId = response.data.obj
              if (this.ruleForm.apartmentOperatorType === 1) {
                this.dialogFormVisible = true
              } else {
                this.dialogTableVisible = true
              }
            } else {
              alert(response.data.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    getcode() {
      this.ruleForm.type = 1
      this.axios.get('http://127.0.0.1/api/sys/wish/sys-login/getCode', { params: this.ruleForm }).then((response) => {

      })
    },
    submitForm2(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.dialogTableVisible = false
          this.dialogFormVisible = false
          this.form.type = this.ruleForm.apartmentOperatorType
          this.form.corporation = this.ruleForm.username
          this.form.userId = this.ruleForm.userId
          this.axios.post('http://127.0.0.1/api/sys/wish/business/add', this.form).then((response) => {
            if (response.data) {
              alert('请等待管理员审核!!')
            } else {
              alert('注册失败!!')
            }
          })
        } else {
          return false
        }
      })
    },
    resetForm2(formName) {
      this.$refs[formName].resetFields()
    }
    // afterQRScan() {
    //   if (e.key === 'x-admin-oauth-code') {
    //     const code = getQueryObject(e.newValue)
    //     const codeMap = {
    //       wechat: 'code',
    //       tencent: 'code'
    //     }
    //     const type = codeMap[this.auth_type]
    //     const codeName = code[type]
    //     if (codeName) {
    //       this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
    //         this.$router.push({ path: this.redirect || '/' })
    //       })
    //     } else {
    //       alert('第三方登录失败')
    //     }
    //   }
    // }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
.regis-form{
  position: relative;
  width: 520px;
  max-width: 100%;
  padding: 1px 35px 0;
  margin: 0 auto;
  overflow: hidden;
}
</style>
